home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Crypto⁄Encryption / TV (CANAL+) decoder.sit / Premium (CANAL+) decoder / Prefs.c < prev    next >
C/C++ Source or Header  |  1998-11-05  |  9KB  |  394 lines

  1. /*
  2.       Premium v0.1
  3.  
  4.       © InMarv from Cologne : greetings to everyone..
  5.       
  6.       Modified by SkRf from Tahiti (5/11/98)
  7. */
  8.  
  9. #include <Errors.h>
  10.  
  11. #include <Types.h>
  12. #include <Memory.h>
  13. #include <Quickdraw.h>
  14. #include <Fonts.h>
  15. #include <Events.h>
  16. #include <Menus.h>
  17. #include <Windows.h>
  18. #include <TextEdit.h>
  19. #include <Dialogs.h>
  20. #include <OSUtils.h>
  21. #include <ToolUtils.h>
  22. #include <SegLoad.h>
  23. #include <Files.h>
  24. #include <stdio.h>
  25. #include <Controls.h>
  26. #include <NameRegistry.h>
  27. #include <math.h>
  28. #include <QDOffscreen.h>
  29. #include <Movies.h>
  30. #include <QuickTimeComponents.h>
  31.  
  32. #include "nagra.h"
  33.  
  34. void Premium();
  35.  
  36. /* Prototypes */
  37.  
  38. void Initialize(void);
  39. void Handle_Menu_Choice( long menu_choice);
  40.  
  41.  
  42. MenuHandle    Applemenu, Filemenu;
  43. Boolean All_Done = FALSE;
  44. DialogPtr    myDialog, AboutDiag;
  45.  
  46. short        theItem, thePart;
  47. EventRecord    TheEvent;
  48. WindowPtr    theWindow;
  49. Rect        itemrect;
  50. Handle        item;
  51. short        itemtype;
  52. short        oldvalue,i, chr;
  53.  
  54. short gFullPal    = 0;
  55. short gSVHS        = 1;
  56. short gSTD      = 1;
  57. short g32bit    = 0;
  58.  
  59. int main(void)
  60. {
  61. Handle        myMenu;
  62. long        menu_choice;
  63. SysEnvRec    theWorld;
  64. int            dummy;
  65. OSErr        error;
  66. GrafPtr        oldPort;
  67.  
  68.  
  69.     Initialize();
  70.  
  71.     myDialog = GetNewDialog( 128, 0L, (WindowPtr)-1L);
  72.     if (myDialog == 0L) return;
  73.  
  74.  
  75.     myMenu = GetNewMBar(128);
  76.     SetMenuBar(myMenu);
  77.     DisposeHandle(myMenu);
  78.     Applemenu = GetMenuHandle(128);
  79.     AppendResMenu( Applemenu, 'DRVR');
  80.  
  81.     DrawMenuBar();
  82.  
  83.     ShowWindow(myDialog);
  84.     GetPort(&oldPort);                                      /* save the environment */
  85.     SetPort(myDialog);                                        /* enable drawing on the dialog */
  86.     GetDialogItem(myDialog,1,&itemtype,&item, &itemrect);    /* get the 'OK' Button rect */
  87.     
  88.     /* Write the default button */
  89.     
  90.     PenSize(3,3);
  91.     InsetRect(&itemrect, -4, -4);
  92.     FrameRoundRect(&itemrect, 16, 16);
  93.     PenSize(1,1);
  94.  
  95.     SetPort(oldPort);    /* restores the old port */
  96.  
  97.     while (All_Done == FALSE)
  98.     {
  99.         WaitNextEvent( everyEvent, &TheEvent, 0L, 0L);
  100.         if (IsDialogEvent (&TheEvent))
  101.         {
  102.             if (  (TheEvent.what == keyDown )
  103.                 &&((TheEvent.modifiers & cmdKey)!=0)
  104.                )
  105.             {
  106.                 switch ( TheEvent.message & charCodeMask)
  107.                 {
  108.                     case 'q':
  109.                     case 'w':
  110.                                 All_Done = TRUE;
  111.                                 break;
  112.                 }
  113.             }
  114.             if ( DialogSelect( &TheEvent, &myDialog, &theItem))
  115.             {
  116.                 switch (theItem)
  117.                 {
  118.                     case 5: /* full pal */
  119.                             GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
  120.                             oldvalue = GetControlValue( (ControlHandle)item);
  121.                             SetControlValue((ControlHandle)item,(oldvalue+1)&1);
  122.                             gFullPal = (oldvalue+1)&1;
  123.                             SetDialogItem(myDialog,theItem,itemtype,item,&itemrect);
  124.                             break;
  125.                     case 6: /* 32 bit digitizing */
  126.                             GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
  127.                             oldvalue = GetControlValue( (ControlHandle)item);
  128.                             g32bit = (oldvalue+1)&1;
  129.                             SetControlValue((ControlHandle)item,(oldvalue+1)&1);
  130.                             SetDialogItem(myDialog,theItem,itemtype,item,&itemrect);
  131.                             break;
  132.                     case 7: /* asnyc digitizing */
  133.                             GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
  134.                             oldvalue = GetControlValue( (ControlHandle)item);
  135.                             SetControlValue((ControlHandle)item,(oldvalue+1)&1);
  136.                             SetDialogItem(myDialog,theItem,itemtype,item,&itemrect);
  137.                             break;
  138.                     case 1: /* start */
  139.                             All_Done = TRUE;
  140.                             Premium();
  141.                             break;
  142.                     case 3: /* SVHS  -  FBAS */
  143.                             GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
  144.                             gSVHS = GetControlValue( (ControlHandle)item);
  145.                             break;
  146.                     case 9: /* SVHS  -  FBAS */
  147.                             GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
  148.                             gSTD = GetControlValue( (ControlHandle)item);
  149.                             break;
  150.                 }
  151.             }            
  152.         } else {
  153.             switch (TheEvent.what)
  154.             {
  155. /*                case nullEvent:
  156.                     DoIdle( &TheEvent );
  157.                     break;
  158. */                case keyDown:
  159.                     All_Done = TRUE;
  160.                     chr = TheEvent.message & charCodeMask;
  161.                     if ((TheEvent.modifiers & cmdKey)!=0)
  162.                     {
  163.                         if (TheEvent.what != autoKey)
  164.                         {
  165.                             menu_choice = MenuKey (chr);
  166.                             Handle_Menu_Choice(menu_choice);
  167.                         }
  168.                     }
  169.                     break;
  170.                 case mouseDown:
  171.                     thePart = FindWindow(TheEvent.where, &theWindow);
  172.                     switch (thePart)
  173.                     {
  174.                         case inMenuBar:
  175.                             menu_choice = MenuSelect(TheEvent.where);
  176.                             Handle_Menu_Choice(menu_choice);
  177.                             break;
  178.                         case inSysWindow:
  179.                             SystemClick( &TheEvent, theWindow);
  180.                             break;
  181.                         case inDrag:
  182.                             DragWindow(theWindow, TheEvent.where, &qd.screenBits.bounds);
  183.                             break;
  184.                         case inGoAway:
  185.                             if (TrackGoAway (theWindow, TheEvent.where))
  186.                                     All_Done = TRUE;
  187.                             break;
  188.                         case inContent:
  189.                             if (theWindow != FrontWindow()) SelectWindow(theWindow);
  190.                             break;
  191.                     }
  192.                     break;
  193.                 case updateEvt:
  194.                     break;
  195.  
  196.             }
  197.         }
  198.     }
  199.  
  200.     CloseWindow(myDialog);
  201. }
  202.  
  203. /* 
  204. //    Initialize everything for the program, make sure we can run
  205. */
  206.  
  207. void Initialize(void)
  208. {
  209.     WindowPtr    mainPtr;
  210.     OSErr        error;
  211.     SysEnvRec    theWorld;
  212.         
  213.     /*
  214.     //    Test the computer to be sure we can do color.  
  215.     //    If not we would crash, which would be bad.  
  216.     //    If we can’t run, just beep and exit.
  217.     */
  218.  
  219.     error = SysEnvirons(1, &theWorld);
  220.     if (theWorld.hasColorQD == false) {
  221.         SysBeep(50);
  222.         ExitToShell();                    /* If no color QD, we must leave. */
  223.     }
  224.     
  225.     /* Initialize all the needed managers. */
  226.     InitGraf(&qd.thePort);
  227.     InitFonts();
  228.     InitWindows();
  229.     InitMenus();
  230.     TEInit();
  231.     InitDialogs(nil);
  232.     InitCursor();
  233. }
  234.  
  235. void Handle_Menu_Choice( long menu_choice)
  236. {
  237. int    the_menu, the_menu_item;
  238. Str255    desk_acc_name;
  239. int    desk_ac_no;
  240.  
  241.     if (menu_choice != 0)
  242.     {
  243.         the_menu = HiWord(menu_choice);
  244.         the_menu_item = LoWord(menu_choice);
  245.         switch(the_menu)
  246.         {
  247.             case 128:
  248.                 if (the_menu_item == 1)
  249.                 {
  250.                 } else {
  251.                     GetMenuItemText( Applemenu, the_menu_item, desk_acc_name);
  252.                     desk_ac_no = OpenDeskAcc( desk_acc_name);
  253.                 }
  254.                 break;
  255.             case 129:
  256.                 All_Done = true;
  257.                 break;
  258.         }
  259.         HiliteMenu(0);
  260.     }
  261.  
  262. }
  263.  
  264. void Premium()
  265. {
  266.     long                err;
  267.     AliasHandle            alias;
  268.     short                i;
  269.  
  270. /* vdig thingies */
  271.     Component                vThing;
  272.     ComponentDescription    vThingDesc;
  273.     ComponentInstance        vThingInst;
  274.     Rect                    maxSrcRect, activeRect, globalRect;
  275.     PixMapHandle            videoPixMapH;
  276.     int                     sx, sy, sbpp, image_size;
  277.     unsigned char            *buffer=NULL, *addr=NULL;
  278.     unsigned char            *base;
  279.     int                     width, flags, posx, posy;
  280.     int                     pal, grab, allkeys, decoder;
  281.     unsigned char            *lines[YSIZE];
  282.  
  283. /* offscreen */
  284.     GrafPtr            origPort;
  285.     GDHandle        origDev;
  286.     QDErr            myErr;
  287.     GWorldPtr        myOffGWorld;
  288.     PixMapHandle    offPixMapHandle  ;
  289.     Boolean            good;
  290.     Rect            sourceRect, destRect;
  291.     GDevice          **MainDevice;
  292.  
  293.     pal = 1;        /* pal decoding */
  294.     allkeys = 1;    /* preselect keys */
  295.     decoder = 1;
  296.  
  297.     MainDevice = GetMainDevice();
  298.  
  299.             SetWTitle(myDialog, "\pComputing Tables...");
  300.             vThingDesc.componentType = 'vdig';
  301.             vThingDesc.componentSubType = 0;
  302.             vThingDesc.componentManufacturer = 0;
  303.             vThingDesc.componentFlags = 0;
  304.             vThingDesc.componentFlagsMask = 0;
  305.             vThing = FindNextComponent((Component) 0, &vThingDesc);
  306.             vThingInst = OpenComponent(vThing);
  307.  
  308.             if (vThingInst == 0) goto bail;
  309.  
  310.             if (gSVHS == 1)
  311.                 VDSetInput(vThingInst, sVideoIn);
  312.             else
  313.                 VDSetInput(vThingInst, compositeIn);
  314.             
  315.             VDSetInputStandard(vThingInst, gSTD);
  316.  
  317.             VDGetMaxSrcRect(vThingInst, gSTD, &maxSrcRect);
  318.             VDGetActiveSrcRect(vThingInst, gSTD, &activeRect);
  319.             VDSetDigitizerRect(vThingInst, &activeRect);
  320.     
  321.             videoPixMapH = (PixMapHandle) NewHandle(sizeof(PixMap));
  322.             **videoPixMapH = **((**MainDevice).gdPMap);
  323.  
  324.             VDSetPlayThruOnOff(vThingInst, vdPlayThruOff);
  325.  
  326.             sourceRect.top        = 0;
  327.             sourceRect.left        = 0;
  328.             sourceRect.right    = 768/2;
  329.             sourceRect.bottom    = 576/2;
  330.             destRect            =    sourceRect;
  331.  
  332.             GetGWorld((struct CGrafPort **)(&origPort), &origDev);
  333.         if (g32bit)
  334.             myErr = NewGWorld(&myOffGWorld, 32,    /* create offscreen graphics world, */
  335.                             &sourceRect,
  336.                             0, 0, 0);
  337.         else
  338.             myErr = NewGWorld(&myOffGWorld, 16,    /* create offscreen graphics world, */
  339.                             &sourceRect,
  340.                             0, 0, 0);
  341.  
  342.             if (myErr == noErr)
  343.             {
  344.                 SetGWorld(myOffGWorld, 0);
  345.                 offPixMapHandle = GetGWorldPixMap(myOffGWorld);
  346.                 if (offPixMapHandle == 0) goto bail;
  347.                 LockPixels(offPixMapHandle);
  348.                 VDSetPlayThruDestination(vThingInst, offPixMapHandle, &sourceRect, nil, nil);
  349.                 SetGWorld((struct CGrafPort *)origPort, origDev);
  350.             } else goto bail;
  351.  
  352.             init_decode_nagra();
  353.  
  354.             sx = 384; sy = 576/2; sbpp = 2;
  355.             width = ((**videoPixMapH).rowBytes);
  356.             width &= 0xfff;
  357.             width /= 2;
  358.             addr = (unsigned char *)(**offPixMapHandle).baseAddr;
  359.             base = (unsigned char *)(**videoPixMapH).baseAddr;
  360.  
  361.             posx = 0;
  362.             posy = 0;
  363.             allkeys = 1;
  364.  
  365.             pal = 0;
  366.  
  367. #define TOPSHIFT    32
  368.         if (g32bit)
  369.         {
  370.             for (i = 0; i < TOPSHIFT; i++)  lines[i]        = addr+(sx+4)*(YSIZE-TOPSHIFT + i)*4;
  371.             for (i = 0; i < YSIZE-TOPSHIFT; i++) lines[i + TOPSHIFT]    = addr+(sx+4)*i*4;
  372.         } else {
  373.             for (i = 0; i < TOPSHIFT; i++)  lines[i]        = addr+(sx+8)*(YSIZE-TOPSHIFT + i)*2;
  374.             for (i = 0; i < YSIZE-TOPSHIFT; i++) lines[i + TOPSHIFT]    = addr+(sx+8)*i*2;
  375.         }
  376.  
  377.             SetWTitle(myDialog, "\pDecoding... click mouse to stop.");
  378.  
  379.             while (!Button()) {
  380.                 err = VDGrabOneFrame(vThingInst);
  381.  
  382.                 if (err != noErr) goto bail;
  383.                 decode_frame(base + (width * posy + posx) * 2,width,lines,
  384.                             sx,sy,1,gFullPal,g32bit);
  385.             }
  386.  
  387.             CloseComponent(vThingInst);
  388.  
  389.             UnlockPixels(offPixMapHandle);
  390.             DisposeGWorld(myOffGWorld);
  391.  
  392. bail:
  393.     return;
  394. }